import logging
from functools import partial

from PyQt5.QtWidgets import QTableWidgetItem, QHeaderView

from .pagevac_base import SubPageWithTableVac
from ioslave.slave import get_pin_value, get_pin_forced_value

LIST_IO_UDF_MARK = []

class UDF_PageVac(SubPageWithTableVac):
    def __init__(self, parent=None):
        super().__init__(parent)

    def table_data_update(self, table_wx):
        list_iopin = LIST_IO_UDF_MARK

        self.table_data_clear(table_wx)  # 清空数据

        row_index = -1
        for iopin in list_iopin:
            row_index += 1
            list_column_strings = [
                str(iopin),
                "未查询到测试说明",
                get_pin_value(iopin),
                get_pin_forced_value(iopin),
            ]
            table_wx.insertRow(row_index)  # 动态添加行
            for column_index in range(len(list_column_strings)):
                # 动态写入单元格数据
                table_wx.setItem(row_index, column_index, 
                        QTableWidgetItem(list_column_strings[column_index]))

    def table_showing_style(self, table_wx):
        header = table_wx.horizontalHeader()
        for column_index in range(len(self.subpage_mapping)):
            header.setSectionResizeMode(column_index, QHeaderView.ResizeToContents)
